package ckw.database;

import java.util.List;

import ckw.database.model.AdministratorToken;
import ckw.database.model.Election;
import ckw.database.model.ElectionChanges;
import ckw.database.model.ElectionNode;
import ckw.database.model.ElectionNonResidentVoter;
import ckw.database.model.ElectionResidentVoter;
import ckw.database.model.Member;
import ckw.database.model.MessageReceived;
import ckw.database.model.MessageToSend;
import ckw.database.model.Node;
import ckw.database.model.NodeChanges;
import ckw.database.model.Vote;
import ckw.database.model.Voter;
import core.communication.message.Message;
import core.database.ElectionStatus;
import core.database.NodeType;
import core.exceptions.ObjectDeleteException;
import core.exceptions.ObjectUpdateException;

public interface DatabaseService {
	/* Node */

	public Node getMainNode();

	public Node storeNode(Node node);

	public void deleteNode(Node node) throws ObjectDeleteException;

	public Node getBaseNode();

	public Node getNode(Long id);

	public Node getNode(String locatorUri);

	public List<Node> getAllNodesByType(NodeType type);

	public Boolean isNodeLocatorUriTaken(String ip, String port);

	public List<Node> getAllNodesByLevel(int level);

	/* MessageToSend */

	public List<MessageToSend> getMessagesToSend();

	public void removeMessageToSend(Long messageToSendDatabaseId);

	public void storeMessageToSend(Message message);

	/* MessageReceived */

	public List<MessageReceived> getMessagesReceived();

	public void storeReceivedMessage(Message message);

	public void setMessageAsHandled(Long id);

	/* NodeChanges */

	public NodeChanges storeNodeChanges(NodeChanges nodesChange);

	public void deleteNodeChanges(NodeChanges change);

	public NodeChanges getNodeChanges(String locatorURI);

	public List<NodeChanges> getAllNodeChanges();

	/* Member */

	public Boolean isMemberIdentificationFieldTaken(String identificationField);

	public List<Member> getAllMembers();

	public Member storeMember(Member member) throws ObjectUpdateException;

	public void deleteMember(Member member) throws ObjectDeleteException;

	/* Election */

	public Election getElection(Long id);

	public Election storeElection(Election election);

	public void deleteElection(Election election) throws ObjectDeleteException;

	public List<Election> getAllElections();

	/* ElectionNode */

	public ElectionNode findElectionNodeByElectionAndNode(Election election, Node node);

	public ElectionNode changeElectionNodeStatus(Long electionId, ElectionStatus status, String locatorURI);

	/* Voter */

	public Voter storeVoter(Voter voter) throws ObjectUpdateException;

	public Boolean isVoterIdentificationFieldTaken(String identificationField);

	public void deleteVoter(Voter voter) throws ObjectDeleteException;

	public List<Voter> getAllVoters();

	public List<Voter> findVotersLike(String text);

	public Voter getVoterByIdentificationField(String identificationField);

	/* ElectionNonResidentVoter */

	public ElectionNonResidentVoter findNonResidentVoterByVoterAndElection(Voter voter, Election election);

	public Boolean verifyVoter(Long electionIdentificationField, String voterIdentificationField);

	/* ElectionResidentVoter */

	public ElectionResidentVoter findResidentVoterByVoterAndElectionNode(Voter voter, ElectionNode electionNode);

	/* AdministratorToken */

	public AdministratorToken findAdministratorTokenByMemberAndElectionNode(Member member, ElectionNode electionNode);

	public AdministratorToken storeAdministratorToken(AdministratorToken token);

	/* ElectionChanges */

	public ElectionChanges storeElectionChanges(ElectionChanges electionChanges);

	public ElectionChanges getElectionChanges(String nodeUri, Long electionIdentificationField);

	public List<ElectionChanges> getAllElectionChages();

	public void deleteElectionChanges(ElectionChanges changes);

	public List<ElectionChanges> getAllElectionChages(Long electionIdentificationField);

	public List<Vote> saveVotes(Long electionIdentificationField, List<Vote> vote);

	public Election getElectionByIdentificationField(Long electionIdentificationField);

	public void updateVotes(List<Vote> votes);

	public List<Vote> getUnparsedVotes();

	public void updateElectionResidentVoter(ElectionResidentVoter voter);

	public ElectionResidentVoter getResidentVoterByVoterIdentificationFieldAndElectionIdentificationField(String vId, Long electionIdentificationField);
}
